package com.ihr360.excel.vo;

import com.ihr360.commons.model.type.ProgressType;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Map;

/**
 * 导入流程上下文
 *
 * @author richey
 */
public class ProgressContext implements Serializable {

    private ProgressContextFile file;

    private String companyId;

    private String userId;

    /**
     * 业务模块code
     */
    private String moduleCode;

    /**
     * 业务唯一标识
     */
    private String businessUniqueKey = "defaultBusinessKey";

    /**
     * 文件服务返回的文件Id
     */
    private String fileId;

    /**
     * 校验器的名字
     */
    private String validatorName;

    private Map<String, Object> extraParams;

    /**
     * 是否只下载错误数据
     */
    private boolean onlyErrorDownload;

    /**
     * 手机号所在列
     */
    private int mobileColNum;


    /**
     *
     */
    private int staffNameNum;


    public ProgressContext() {
    }

    public ProgressContext(String companyId, String userId, String moduleCode, String businessUniqueKey, ProgressContextFile contextFile) {
        this.companyId = companyId;
        this.userId = userId;
        this.moduleCode = moduleCode;
        if (StringUtils.isNotEmpty(businessUniqueKey)) {
            this.businessUniqueKey = businessUniqueKey;
        }
        this.file = contextFile;
    }

    public String getCompanyId() {
        return companyId;
    }

    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getModuleCode() {
        return moduleCode;
    }

    public void setModuleCode(String moduleCode) {
        this.moduleCode = moduleCode;
    }

    public String getBusinessUniqueKey() {
        return businessUniqueKey;
    }

    public ProgressContextFile getFile() {
        return file;
    }

    public void setFile(ProgressContextFile file) {
        this.file = file;
    }

    public String getFileId() {
        return fileId;
    }

    public void setFileId(String fileId) {
        this.fileId = fileId;
    }


    public String getValidatorName() {
        return validatorName;
    }

    public void setValidatorName(String validatorName) {
        this.validatorName = validatorName;
    }

    public boolean isOnlyErrorDownload() {
        return onlyErrorDownload;
    }

    public void setOnlyErrorDownload(boolean onlyErrorDownload) {
        this.onlyErrorDownload = onlyErrorDownload;
    }

    public String getProgressKey() {
        return String.join(":", ProgressType.EXCEL_HANDLE.toString(), companyId, userId, moduleCode, businessUniqueKey);
    }

    public Map<String, Object> getExtraParams() {
        return extraParams;
    }

    public void setExtraParams(Map<String, Object> extraParams) {
        this.extraParams = extraParams;
    }

    public int getMobileColNum() {
        return mobileColNum;
    }

    public void setMobileColNum(int mobileColNum) {
        this.mobileColNum = mobileColNum;
    }

    public int getStaffNameNum() {
        return staffNameNum;
    }

    public void setStaffNameNum(int staffNameNum) {
        this.staffNameNum = staffNameNum;
    }

    public static ProgressContext getInstanceByProgressKey(String progressKey) {
        if (StringUtils.isEmpty(progressKey)) {
            return new ProgressContext();
        }

        String[] keyItems = progressKey.split(":");
        if (keyItems.length != 5) {
            return new ProgressContext();
        }
        ProgressContext progressContext = new ProgressContext(keyItems[1], keyItems[2], keyItems[3], keyItems[4], null);
        return progressContext;
    }


}
